package com.sskj.bibi.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.bibi.bean.EntrustBean;
import com.sskj.bibi.ui.activity.AllEntrustActivity;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;


public class AllEntrustActivityPresenter extends BasePresenter<AllEntrustActivity> {


    public Flowable<List<EntrustBean>> getEntrustList(int page,String qu) {

        return httpService.getBibiTradeRecord(null,null,"3",page,qu)
                .converter(new JsonConverter<HttpData<PageBean<EntrustBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList())
                .onErrorReturnItem(new ArrayList<>());

    }



    public void cancelEntrust(String orderId) {
        httpService.cancelCoinOrder( orderId)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        mView.cancelReturn();
                    }
                });
    }
}
